package main

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	beego.BConfig.WebConfig.Session.SessionOn = true
	// 注册驱动
	orm.RegisterDriver("mysql", orm.DRMySQL)
	dbUserName := beego.AppConfig.String("dbUserName")
	dbPwd := beego.AppConfig.String("dbPwd")
	dbUrl := beego.AppConfig.String("dbUrl")
	dbName := beego.AppConfig.String("dbName")
	recordDbName := beego.AppConfig.String("recordDbName")
	orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8", dbUserName, dbPwd, dbUrl, dbName))
	orm.RegisterDataBase("record", "mysql", fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8", dbUserName, dbPwd, dbUrl, recordDbName))
}

func main() {
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.Run()
}
